    var btn = document.getElementById("btn");
    var username = document.getElementById("username");
    var password = document.getElementById("password");

    btn.onclick = async function(){
        var options = {
            url :"http://127.0.0.1:8888/users/login",
            type :"POST",
            data :{
                username:username.value,
                password:password.value
            }
        }
    let data = await ajax_promise(options)
    console.log(data);

    data = JSON.parse(data);

    switch(data.code){
        case 0 :
            errorTip(data.message);
            break;
        case 1 :
            successTip(data.message);
          
            setTimeout(function(){
                location.href = "ikea.html"
            },1000)
        
    setCookie("userid",data.user.id);
    setCookie("token",data.token,{
            expires:1
    });
        break;
    }

    }
    
    var login_tip = document.getElementById("login_tip");

    function errorTip(msg){
        login_tip.style.display = "block";
       
        login_tip.innerHTML = msg;

        setTimeout(function(){
            login_tip.style.display = "none";
        },1000)
    }
    function successTip(msg){

        login_tip.style.display = "block";
        login_tip.innerHTML = msg;

        setTimeout(function(){
            login_tip.style.display = "none"
        },1000)

    }
